<template>
    <div class="login">
        登录页面
        <el-input v-model="loginInfo.username" placeholder="username" />
        <el-input v-model="loginInfo.password" placeholder="password" />
        <el-button type="primary" @click="Login">登录</el-button>
    </div>
</template>

<script setup lang="ts">
import useStore from "@/store";
import { login, getUserInfo, getRoute } from "@/api/user"
import { reactive } from "vue";
import { setLocal } from "@/utils/localStore"
import { useRoute, useRouter } from "vue-router";
import { getMenu } from "@/utils/menuRoute"
const router = useRouter();
const { user, roleRoute } = useStore();
interface loginConfig {
    username: string;
    password: string;
}
const loginInfo: loginConfig = reactive({
    username: '',
    password: ''
})

const Login = async () => {
    // worker1 123321 13 admin 123321 1  larry 123321 3 moon 123321 4
    const { data: {
        token
    } } = await login(loginInfo)
    // 存储token
    setLocal("token", token)
    const userInfo = await getUserInfo()
    // 存储用户信息
    setLocal("userInfo", JSON.stringify(userInfo.data))
    user.saveUserInfo(userInfo.data)
    // 存储用户权限id
    const { data: {
        role_id
    } } = userInfo
    setLocal("userRole", role_id)
    user.saveRole(role_id)
    // 存储路由
    // await getMenu(role_id)
    // const { data } = await getRoute({ id: role_id })
    // console.log(data)
    // setLocal("roleRoute", JSON.stringify(data))
    // roleRoute.saveRoute(data)
    router.push("/dashboard")
}

</script>

<style scoped lang="scss">
</style>